<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<h1>处理器方法入参</h1>
<p>逐个请求参数</p>
<form action="user/login" method="get">
    账号：<input type="text" name="account">
    <br>
    密码：<input type="text" name="password">
    <br>
    <input type="submit" value="提交">
</form>
<hr>
<p>使用对象请求参数</p>
<form action="user/loginTakeObject" method="post">
    账号：<input type="text" name="account">
    <br>
    密码：<input type="text" name="password">
    <br>
    <input type="submit" value="提交">
</form>
<h1>处理器方法出参</h1>
<a href="user/doMain">进入main页面</a>

<p>Ajax响应JSON returnVoid</p>
<button id="getJsonReturnVoid">获取JSON数据</button>
<p>Ajax响应JSON returnObject</p>
<button id="getJsonReturnObject">获取JSON数据</button>
<br>
<textarea id="jsonData"></textarea>

<script src="./static/js/jquery-3.5.1.js"></script>
<script !src="">
    $(function () {
        $("#getJsonReturnVoid").click(function () {
            $.ajax({
                url: "user/getJsonByReturnVoid",
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data != null) {
                        $("#jsonData").val("");
                        $("#jsonData").val(data.account + "=====" + data.password);
                    }
                }
            })
        });

        $("#getJsonReturnObject").click(function () {
            $.ajax({
                url: "user/getJsonByReturnObject",
                type: "post",
                dataType: "json",
                success: function (data) {
                    let json = "";
                    if (data != null && data.length > 1) {
                        console.log(data);
                        $("#jsonData").val("");
                        $.each(data, function (index, item) {
                            json += item.account + "====" + item.password;
                        })
                        $("#jsonData").val(json);
                    }
                }
            })
        });
    })
</script>
</body>
</html>
